var mysql=require('mysql');
var $conf=require('../conf/db.js');
var $util=require('../util/util.js');
var $sql=require('./adminsql.js');
//使用连接池
var pool  = mysql.createPool($util.extend({}, $conf.mysql));

// 向前台返回JSON方法的简单封装
var jsonWrite = function (res, ret) {
    if(typeof ret === 'undefined') {
        res.json({
            code:'1',
            msg: '操作失败'
        });
    } else {
        res.json(ret);
    }
};

var adminopt = {
    //查
    adminpwd: function (req,res,next) {
        var account = +req.query.account;
        pool.getConnection(function (err,connection) {
            connection.query($sql.adminpwd,account, function(err, result) {
                jsonWrite(res, result);
                connection.release();//释放连接
            });
        })
    }
}

module.exports = adminopt;
